import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Random;

public class GuessNumber {
    public static void main(String[] args) {
        Random random = new Random();
        int randomNumber = random.nextInt(101);// 101为要生成随机数的范围在0<=n<101,nextInt返回下一个伪随机数在0~100（包括）
        int guessNumber = -1;
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); // 使比特输入转换成缓冲字符输入
        int count = 0;
        System.out.println("请输入0~100之间的整数：");
        while (guessNumber != randomNumber) {
            try {
                guessNumber = Integer.parseInt(input.readLine());// 从键盘获取一行字符并转换为整数赋值给guessNumber
                if (guessNumber < 0 || guessNumber > 100) {
                    System.out.println("请输入一个0~100之间的整数：");
                    count++;
                    continue;
                }
            } catch (NumberFormatException e) {
                System.out.println("再次提醒,请输入一个0~100之间的整数：");
                count++;
                continue;
            } catch (IOException e) {
                System.out.println("不听话的后果就是我不陪你玩了，再见宝贝！");
                e.printStackTrace();
            }
            if (guessNumber > randomNumber)
                System.out.println("哎呀，大了！来呀再猜呀：");
            if (guessNumber < randomNumber)
                System.out.println("阿喔，小了！来呀再猜呀：");
            count++;
        }
        System.out.println("Bingo！恭喜你猜对啦！您共猜了" + count + "次。");
    }
}
